﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CarLoanSystem.Entity;

namespace CarLoanSystem
{
    public partial class frmEditCarModel : Form
    {
        private static CarModelItem carModelItem;
        public frmEditCarModel(int id)
        {
            InitializeComponent();
            this.cbbCarBrand.DataSource = DAL.CarBrandInfoDAL.LoadAllForComboBox();
            this.cbbCarBrand.DisplayMember = "CAR_BRAND_NAME";
            this.cbbCarBrand.ValueMember = "CAR_BRAND_ID";
            carModelItem = DAL.CarModelInfoDAL.LoadCarModel(id);
            this.txtModelName.Text = carModelItem.CAR_MODEL_NAME;
            this.cbbCarBrand.SelectedValue = carModelItem.CAR_BRAND_ID;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            carModelItem.CAR_BRAND_ID = Convert.ToInt32(this.cbbCarBrand.SelectedValue.ToString());
            carModelItem.CAR_MODEL_NAME = this.txtModelName.Text;
            DAL.CarModelInfoDAL.Update(carModelItem);
            MessageBox.Show("บันทึกข้อมูลเรียบร้อย","ข้อมูลรุ่นรถยนต์");
            this.Close();
        }
    }
}
